%% 2D growth timelapse analysis
% collected 01/15/13
%{

Steps:
1. Mount casalim volume 'lim-alt'
2. matpath = read_nd2('/Volumes/lim-alt/Microscopy/Thomas/Yeast/011513_cluster_dynamics/011513_yTS27g-39_growth_t4.nd2');
    or select from dialog.
   Time to complete ~ 0.54h
3. matpath = read_nd2('/Volumes/lim-alt/Microscopy/Thomas/Yeast/011513_cluster_dynamics/011513_yTS27g-39_growth_t6h.nd2');
    Time to complete ~ 
** after series 26, Writing to MAT took ~1000 instead of 200s, ps 'stuck', in htop, MEM is at max, but matlab%mem ~20. 
** after series 34, stopped running: (index 6223:end blank)
Error using loci.formats.ChannelSeparator/openBytes
Java exception occurred:
java.io.IOException: Bad file descriptor
	at java.io.RandomAccessFile.length(Native Method)
	at loci.common.NIOFileHandle.length(NIOFileHandle.java:206)
	at loci.common.NIOFileHandle.buffer(NIOFileHandle.java:522)
	at loci.common.NIOFileHandle.seek(NIOFileHandle.java:254)
	at loci.common.RandomAccessInputStream.seek(RandomAccessInputStream.java:129)
	at loci.formats.in.NativeND2Reader.openBytes(NativeND2Reader.java:203)
	at loci.formats.DelegateReader.openBytes(DelegateReader.java:197)
	at loci.formats.ImageReader.openBytes(ImageReader.java:414)
	at loci.formats.ChannelFiller.openBytes(ChannelFiller.java:197)
	at loci.formats.ChannelSeparator.openBytes(ChannelSeparator.java:226)
	at loci.formats.ChannelSeparator.openBytes(ChannelSeparator.java:159)
	at loci.formats.ChannelSeparator.openBytes(ChannelSeparator.java:143)

Error in bfGetPlane (line 37)
plane = r.openBytes(iPlane - 1);

Error in bfopen_tvs (line 145)
        I_p(:,:,zct(1),zct(3),zct(2)) = bfGetPlane(r, i);

Error in read_nd2 (line 103)
[label_cell,omeMeta] = bfopen_tvs(id,matpath); 

unable to access data with imshow(mat2gray(squeeze(m.I(:,:,1,1,1,1))))
compression issue? initialization issue?

4h matfile is OK for use

--created new matfile to collect time vector and metadata
--get positions 35-40 in third mat file

Rewrote data structure from {c,p}(x,y,z,t) (RAM-intensive) to 6D .mat 
- write too slow, wrote as {p}(x,y,z,t,c) 1/24/13
Re-ran on both files, wrote catmat.m to concatenate mat files on an
interior dimension (time)
Need to update time_v to start from last catted time ~400s
Only 930s to threshold entire catted I from matfile

%}

%{
4. pool data from all 4 mat files (BW only), load into RAM/SWAP and save 

5. props = extractMetrics(matpath);
%}

